<template>
  <div>
    <el-form :inline="true" class="bg-bg_color w-[99/100] pl-4 pt-4">
      <el-form-item label="案例">
        <el-select style="width: 180px" placeholder="请选择" filterable clearable v-model="SearchCaseType">
          <el-option v-for="cs in CaseTypeList" :key="cs.id" :label="cs.displayName" :value="cs.id" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button class="ml-3" type="primary" :icon="useRenderIcon(Search)" :loading="loading" @click="onSearch()">
          搜索
        </el-button>
      </el-form-item>
    </el-form>
    <PureTableBar title="案例管理" class="h100-80">
      <template #buttons>
        <p class="text-red-500 absolute left-[120px] leading-7 text-sm">注：双击查看详情</p>
        <el-button type="primary" :icon="useRenderIcon(AddFill)" @click="DetailsUpdate(undefined)">
          添加
        </el-button>
      </template>
      <template v-slot="{ size, checkList }">
        <pure-table border align-whole="center" highlight-current-row @row-click="RowDblclick" showOverflowTooltip
          table-layout="auto" :loading="loading" size="small" :data="dataList" :columns="columns" :checkList="checkList"
          :pagination="pagination" max-height="200" :header-cell-style="{
            background: 'var(--el-table-row-hover-bg-color)',
            color: 'var(--el-text-color-primary)'
          }" @size-change="handleSizeChange" @current-change="handleCurrentChange" @cell-dblclick="DetailsUpdate">
          <template #operation="{ row }">
            <el-button class="reset-margin" link type="primary" :size="size" :icon="useRenderIcon(EditPen)"
              @click="DetailsUpdate(row)">
              修改
            </el-button>
            <el-button class="reset-margin" link type="danger" :size="size" @click="handleDelete(row)"
              :icon="useRenderIcon(Delete)">
              删除
            </el-button>
            <!-- <el-popconfirm title="是否确认删除?" @confirm="handleDelete(row)">
              <template #reference>
                <el-button class="reset-margin" link type="danger" :size="size" :icon="useRenderIcon(Delete)">
                  删除
                </el-button>
              </template>
            </el-popconfirm> -->
          </template>
        </pure-table>
      </template>
    </PureTableBar>
    <!-- 弹窗 - 新增 or 修改-->
    <el-dialog @close="ClosePanelVisible(UpedateRef)" v-model="UpdateVisible" top="5vh" :title="loadingTitle" width="50%"
      style="min-width: 600px" center :close-on-click-modal="false">
      <el-scrollbar height="600px">
        <el-form :inline="true" :rules="rules" label-width="100px" ref="UpedateRef" label-position="left"
          :model="updatefrom">
          <el-form-item label="案例类别" prop="parentMenuId">
            <el-select style="width: 190px" placeholder="请选择" value-key="parentMenuName" filterable clearable
              v-model="updatefrom.parentMenuId" :disabled="SetDisabled">
              <el-option v-for="cs in CaseTypeList" :key="cs.id" :label="cs.displayName" :value="cs.id" />
            </el-select>
          </el-form-item>
          <br>
          <el-form-item label="案例名称" prop="caseName">
            <el-input type="text" v-model="updatefrom.caseName" />
          </el-form-item>
          <el-form-item label="应用描述" prop="remarks" v-if="UpdateVisible">
            <wang-edior v-model="updatefrom.remarks" :height="200" /></el-form-item>
          <el-form-item label="业务流程" prop="processFlow" v-if="UpdateVisible">
            <wang-edior v-model="updatefrom.processFlow" :height="200" /></el-form-item>
        </el-form>
      </el-scrollbar>
      <template #footer>
        <span class="dialog-footer">
          <el-button type="primary" @click="addCase(UpedateRef)">保存</el-button>
          <el-button @click="ClosePanelVisible(UpedateRef)">取消</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { PureTableBar } from "@/components/RePureTableBar";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import WangEdior from "@/components/wangEditor/index.vue"
import EditPen from "@iconify-icons/ep/edit-pen";
import AddFill from "@iconify-icons/ri/add-circle-line";
import Delete from "@iconify-icons/ep/delete";
import Search from "@iconify-icons/ep/search";
import { useCase } from "./hook";

const {
  rules,
  columns,
  loading,
  dataList,
  SetDisabled,
  CaseTypeList,
  pagination,
  UpdateVisible,
  SearchCaseType,
  loadingTitle,
  UpedateRef,
  updatefrom,
  addCase,
  onSearch,
  RowDblclick,
  handleDelete,
  DetailsUpdate,
  handleSizeChange,
  handleCurrentChange,
  ClosePanelVisible
} = useCase();
</script>


<style scoped lang="scss">
.h100-80 {
  .pure-table {
    height: calc(100% - 60px);

    :deep(.el-table--fit) {
      height: calc(100% - 60px);
    }
  }
}
</style>

